package cn.east196.xfx.controls;

import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;
import javafx.stage.Window;

import java.util.Optional;

import cn.east196.xfx.StagePool;

public class MessageBox {

  public static String WARNING = "Warning";
  public static String INFORMATION = "Information";
  public static String ERROR = "Error";

  public MessageBox() {
  }

  public static Optional<ButtonType> showResult(Window owner, AlertType alertType, String title, String text) {
    Alert alert = new Alert(alertType);
    alert.initOwner(owner);
    alert.setTitle(title);
    alert.setContentText(text);
    alert.setHeaderText(null);
    return alert.showAndWait();
  }

  public static Optional<ButtonType> error(String stageId, String text) {
    Stage owner = StagePool.get(stageId);
    return showResult(owner, AlertType.ERROR, MessageBox.ERROR, text);
  }

  public static Optional<ButtonType> info(String stageId, String text) {
    Stage owner = StagePool.get(stageId);
    return showResult(owner, AlertType.INFORMATION, MessageBox.INFORMATION, text);
  }

  public static Optional<ButtonType> warn(String stageId, String text) {
    Stage owner = StagePool.get(stageId);
    return showResult(owner, AlertType.WARNING, MessageBox.WARNING, text);
  }

}
